@extends('layouts.admin')
@section('content')
    <div id="ribbon"><ol class="breadcrumb"><li>内容区</li></ol></div>
    <div class="content_wrapper">
        <aside>
            <header><i class="fa fa-fw fa-file"></i>公司列表</header>
            <section>
                <div class="row">
                    <div class="col-sm-12">
                        <form action="" method="get">
                            <div class="btn-group">
                                <input type="text" class="form-control" placeholder="用户名" name="username" value="{{request('username')}}">
                            </div>
                            <div class="btn-group">
                                <input type="text" class="form-control" placeholder="公司名" name="name" value="{{request('name')}}">
                            </div>
                            <div class="btn-group">
                                <button class="btn btn-default"><i class="fa fa-filter"></i>查询</button>
                            </div>
                            <div class="btn-group">
                                <a href="{{url('admin/agent/add')}}" class="btn btn-default">
                                    <i class="fa fa-plus"></i>添加
                                </a>
                            </div>
                        </form>
                        <div class="table-responsive" style="margin-top:10px;">
                            <table id="example" class="table table-striped table-bordered table-hover" cellspacing="0"
                                   width="100%">
                                <thead>
                                <tr>
                                    <th>用户名</th>
                                    <th>公司名</th>
                                    <th>店铺名</th>
                                    <th>联系人</th>
                                    <th>联系方式</th>
                                    <th>状态</th>
                                    <th>创建时间</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                    @foreach($list as $value)
                                        <tr>
                                            <td>{{$value['username']}}</td>
                                            <td>{{$value['name']}}</td>
                                            <td>{{$value['shop_name']}}</td>
                                            <td>{{$value['contact']}}</td>
                                            <td>{{$value['tel']}}</td>
                                            <td>{{$value['status'] == 1 ? '正常' : '冻结'}}</td>
                                            <td>{{$value['created_at']}}</td>
                                            <td>
                                                <a href="{{url('admin/agent/edit?id=' . $value['id'])}}" class="btn btn-success btn-xs">编辑</a>
                                                <button type="button" class="btn btn-warning btn-xs" onclick="delRow('{{$value['id']}}')">删除</button>
                                                <button type="button" class="btn btn-success btn-xs" onclick="resetPwd('{{$value['id']}}')">重置密码</button>
                                                <button type="button" class="btn btn-success btn-xs" onclick="showAddress('{{$value['id']}}')">查看地址</button>
                                            </td>
                                        </tr>
                                    @endforeach
                                </tbody>
                            </table>
                        </div>
                        <nav>{!! $list->appends($params)->render() !!}</nav>
                    </div>
                </div>
            </section>
        </aside>
    </div>
    <script>
        function delRow(id) {
            if (confirm('确定要删除吗？')) {
                $.post('{{url('admin/agent/del')}}', {id: id}, function () {
                    location.reload();
                });
            }
        }
        function resetPwd(id) {
            if (confirm('确定要重置该公司的登录密码为 123456 吗？')) {
                $.post('{{url('admin/agent/resetPwd')}}', {id: id}, function (res) {
                    layer.msg(res.info, {icon: res.status});
                });
            }
        }
        function showAddress(id) {
            var str = '公司管理后台地址：http://{{$hostName}}/agent<br>';
            str += '店铺微信端地址：http://' + id + '.{{$hostName}}<br>';
            layer.alert(str)
        }
    </script>
@endsection